package servlet.clazz;

import pojo.Department;
import pojo.LogFamily;
import service.ClazzService;
import service.serviceImpl.ClazzServiceImpl;
import servlet.BaseServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017-12-10.
 */
public class ClazzServlet extends BaseServlet {
    ClazzService clazzService=new ClazzServiceImpl();
    int result=0;
    public String clazzManage(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        //查出所有的日志类别
        List<LogFamily> logFamilyList= clazzService.getAllLogFamily();
        List<Department> departmentList= clazzService.getAllDepartment();
        request.setAttribute("logFamilyList",logFamilyList);
        request.setAttribute("departmentList",departmentList);
        return "/jsp/clazz/clazz.jsp";
    }
    //删除日志的某个类别
    public String deleteClazzLogFamily(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        int id=Integer.parseInt(request.getParameter("id"));
        int result=clazzService.deleteLogFamily(id);
        return "/clazz?method=clazzManage";
    }
    //删除部门的某个类别
    public String deleteClazzDepartment(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        int id=Integer.parseInt(request.getParameter("id"));
        result=clazzService.deleteLogDepartment(id);
        return "/clazz?method=clazzManage";
    }
    //增加日志的类别
    public String addClazzLogFamily(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        String logFamily=request.getParameter("logFamily");
        result=clazzService.addLogFamily(logFamily);
        return "/clazz?method=clazzManage";
    }
    //增加部门的类别
    public String addClazzDepartment(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        String department=request.getParameter("department");
        result=clazzService.addDepartment(department);
        return "/clazz?method=clazzManage";
    }
}
